home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: David Byrden <100101.2547@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Problem with generic classes/templates
- Date: 20 Jan 1996 18:45:45 GMT
- Organization: self-employed
- Message-ID: <4drd8p$2sa@news.bridge.net>
- References: <4dlerb$r3r@finch.doc.ic.ac.uk>
- NNTP-Posting-Host: ppp-mia1-60.bridge.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
-
- >> template <class X> class marzipan<X>{
- >> X ian;
- >> public:
- >> marzipan<X>(/* what goes here? */) { /* and what goes here? */ }
- >> }
-
-
- >> But how do I pass parameters to the constructor function of meringue?
-
- >> I understand that I can use "..." somehow
-
- Using the ellipsis would abandon the compiler's type checking. Your ctor
- would be as unreliable as 'printf'. It would also require you
- to explicitly write specialisations of the ctor for every possible type
- X.
-
- The only general solution is to assume that the class X knows how to copy
- its own values, i.e. it has a public copy constructor. This assumption is
- made throughout the STL.
-
-
- template <class X> class marzipan<X>{
- X ian;
- public:
- marzipan<X>( const X& init_value )
- : ian(init_value) { }
-
- } ;
-
- David
-
-
-
-